﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace KSGJ
{
    public class validationclass:System.Web.UI.Page
    {
        public validationclass() { }
        /// <summary>
        /// session验证
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            if (Session["sessionKey"] == null)
            {
                string path = Page.ResolveUrl("http://container.api.taobao.com/container?appkey=" + System.Configuration.ConfigurationManager.AppSettings["AppKey"].ToString() + "&scope=promotion");
                //string path = Page.ResolveUrl("http://container.api.taobao.com/container?appkey=" + System.Configuration.ConfigurationManager.AppSettings["AppKey"].ToString());
                AlertAndRedirectToTop("您还未登录，请重新登录！", path);
                return;
            }
            if (Session["expires"] == null)
            {
                string path = Page.ResolveUrl("http://container.api.taobao.com/container?appkey=" + System.Configuration.ConfigurationManager.AppSettings["AppKey"].ToString() + "&scope=promotion");
                //string path = Page.ResolveUrl("http://container.api.taobao.com/container?appkey=" + System.Configuration.ConfigurationManager.AppSettings["AppKey"].ToString());
                AlertAndRedirectToTop("您未进行短授权，请重新登录授权！", path);
                return;
            }
            //if (Session["subNick"] == null)
            //{
            //    //if (Session["expires"] == null)
            //    //{
            //    //    //string path = Page.ResolveUrl("http://container.api.taobao.com/container?appkey=" + System.Configuration.ConfigurationManager.AppSettings["AppKey"].ToString() + "&scope=promotion");
            //    //    string path = Page.ResolveUrl("http://container.api.taobao.com/container?appkey=" + System.Configuration.ConfigurationManager.AppSettings["AppKey"].ToString());
            //    //    AlertAndRedirectToTop("您未进行短授权，请重新登录授权！", path);
            //    //    return;
            //    //}
            //}
            base.OnLoad(e);
        }

        /// <summary>
        /// 弹出错误并跳转
        /// </summary>
        /// <param name="message"></param>
        /// <param name="toURL"></param>
        public static void AlertAndRedirectToTop(string message, string toURL)
        {
            string js = "<script language=javascript>alert('{0}');top.window.location.replace('{1}')</script>";
            HttpContext.Current.Response.Write(string.Format(js, message, toURL));
        }
        public static void AlertMessage(string msg)
        {
            string runjs = "<script language=javascript>alert('{0}')</script>";
            HttpContext.Current.Response.Write(string.Format(runjs, msg));
        }
    }
}